package com.fz.controller;

import com.fz.entity.*;
import com.fz.mapper.WebRentMapper;
import com.fz.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Z-C-Y on 2018-03-06.
 * rent.jsp   艺租赁
 */
@Controller
public class WebRentController {
    @Autowired
    public WebRentMapper webRentMapper;

    @RequestMapping("webpage/rent")
    public String rent(Model model, HttpServletRequest req){
        /*显示页面图片*/
        String stu = null;
        List<Rentimage> listRentimage = webRentMapper.queryRentimage();
        for(Rentimage rr:listRentimage ){
            stu= rr.getImagename();
        }
        model.addAttribute("listRentimage",stu);
        /*页面大图旁边的 小商品图*/
        List<Rent> listRent  = webRentMapper.listRent();
        model.addAttribute("listRent",listRent);

        /*画品分类*/
        List<Leaseholds> listLeaseholds = webRentMapper.queryLeaseholds();
        model.addAttribute("listLeaseholds",listLeaseholds);
        /*题材分类*/
        List<Lrice> listLrice = webRentMapper.queryLrice();
        model.addAttribute("listLrice",listLrice);
        /*租赁场所*/
        List<Peinttypes> listPeinttypes = webRentMapper.queryPeinttypes();
        model.addAttribute("listPeinttypes",listPeinttypes);
        /*具体场景*/
        List<Scene> listScene = webRentMapper.queryScene();
        model.addAttribute("listScene",listScene);
        /*价格*/
        List<Prices> listPrices = webRentMapper.queryPrices();
        model.addAttribute("listPrices",listPrices);
        /*分页显示*/
        int  pageNun1 = 1;
        if((req.getParameter("pageNun") != null) && !("".equals(req.getParameter("pageNun")))){
            pageNun1 = Integer.parseInt(req.getParameter("pageNun"));
        }
        //System.out.println("==获得当前是第几页==pageNun===="+req.getParameter("pageNun"));
        //每页显示的记录数
        int pageSize = 10;
        /*分页======查询数据库的数据的总数据*/
        /*得到表中总条数*/
        int totalRecord = listRent.size();
        //有了初始化数据，就可以创建PageBean对象了
        PageBean pbm = new PageBean(pageNun1, pageSize, totalRecord);

        model.addAttribute("pbm",pbm);
        //获取PageBeanManage对象中的startIndex;
        int startIndex = pbm.getStartIndex();

        //有了pageSize和startIndex，就可以拿到每页的数据
        List<Rent> list3Rent =  webRentMapper.queryRentData(startIndex,pageSize);
        model.addAttribute("list3Rent",list3Rent);
        model.addAttribute("t","rent");
        return "webpage/rent";
    }

}
